﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace TierApplication
{
	/// <summary>
	/// 类P_DDCODE。
	/// </summary>
	[Serializable]
	public partial class P_DDCODE
	{
		public P_DDCODE()
		{}
		#region Model
		private string _ddid;
		private string _ddtype;
		private string _codeid;
		private string _codename;
		private decimal? _orderid;
		private string _remark;
		/// <summary>
		/// 
		/// </summary>
		public string DDID
		{
			set{ _ddid=value;}
			get{return _ddid;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string DDTYPE
		{
			set{ _ddtype=value;}
			get{return _ddtype;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string CODEID
		{
			set{ _codeid=value;}
			get{return _codeid;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string CODENAME
		{
			set{ _codename=value;}
			get{return _codename;}
		}
		/// <summary>
		/// 
		/// </summary>
		public decimal? ORDERID
		{
			set{ _orderid=value;}
			get{return _orderid;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string REMARK
		{
			set{ _remark=value;}
			get{return _remark;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public P_DDCODE(string DDID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select DDID,DDTYPE,CODEID,CODENAME,ORDERID,REMARK ");
			strSql.Append(" FROM P_DDCODE ");
			strSql.Append(" where DDID=:DDID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DDID", OracleType.VarChar,50)};
			parameters[0].Value = DDID;

			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["DDID"]!=null && ds.Tables[0].Rows[0]["DDID"].ToString()!="")
				{
					this.DDID=ds.Tables[0].Rows[0]["DDID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["DDTYPE"]!=null && ds.Tables[0].Rows[0]["DDTYPE"].ToString()!="")
				{
					this.DDTYPE=ds.Tables[0].Rows[0]["DDTYPE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CODEID"]!=null && ds.Tables[0].Rows[0]["CODEID"].ToString()!="")
				{
					this.CODEID=ds.Tables[0].Rows[0]["CODEID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CODENAME"]!=null && ds.Tables[0].Rows[0]["CODENAME"].ToString()!="")
				{
					this.CODENAME=ds.Tables[0].Rows[0]["CODENAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ORDERID"]!=null && ds.Tables[0].Rows[0]["ORDERID"].ToString()!="")
				{
					this.ORDERID=decimal.Parse(ds.Tables[0].Rows[0]["ORDERID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["REMARK"]!=null && ds.Tables[0].Rows[0]["REMARK"].ToString()!="")
				{
					this.REMARK=ds.Tables[0].Rows[0]["REMARK"].ToString();
				}
			}
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string DDID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from P_DDCODE");
			strSql.Append(" where DDID=:DDID ");

			OracleParameter[] parameters = {
					new OracleParameter(":DDID", OracleType.VarChar,50)};
			parameters[0].Value = DDID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into P_DDCODE (");
			strSql.Append("DDID,DDTYPE,CODEID,CODENAME,ORDERID,REMARK)");
			strSql.Append(" values (");
			strSql.Append(":DDID,:DDTYPE,:CODEID,:CODENAME,:ORDERID,:REMARK)");
			OracleParameter[] parameters = {
					new OracleParameter(":DDID", OracleType.VarChar,10),
					new OracleParameter(":DDTYPE", OracleType.VarChar,40),
					new OracleParameter(":CODEID", OracleType.VarChar,30),
					new OracleParameter(":CODENAME", OracleType.VarChar,30),
					new OracleParameter(":ORDERID", OracleType.Number,2),
					new OracleParameter(":REMARK", OracleType.VarChar,60)};
			parameters[0].Value = DDID;
			parameters[1].Value = DDTYPE;
			parameters[2].Value = CODEID;
			parameters[3].Value = CODENAME;
			parameters[4].Value = ORDERID;
			parameters[5].Value = REMARK;

			DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update P_DDCODE set ");
			strSql.Append("DDTYPE=:DDTYPE,");
			strSql.Append("CODEID=:CODEID,");
			strSql.Append("CODENAME=:CODENAME,");
			strSql.Append("ORDERID=:ORDERID,");
			strSql.Append("REMARK=:REMARK");
			strSql.Append(" where DDID=:DDID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DDTYPE", OracleType.VarChar,40),
					new OracleParameter(":CODEID", OracleType.VarChar,30),
					new OracleParameter(":CODENAME", OracleType.VarChar,30),
					new OracleParameter(":ORDERID", OracleType.Number,2),
					new OracleParameter(":REMARK", OracleType.VarChar,60),
					new OracleParameter(":DDID", OracleType.VarChar,10)};
			parameters[0].Value = DDTYPE;
			parameters[1].Value = CODEID;
			parameters[2].Value = CODENAME;
			parameters[3].Value = ORDERID;
			parameters[4].Value = REMARK;
			parameters[5].Value = DDID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string DDID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from P_DDCODE ");
			strSql.Append(" where DDID=:DDID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DDID", OracleType.VarChar,50)};
			parameters[0].Value = DDID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(string DDID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select DDID,DDTYPE,CODEID,CODENAME,ORDERID,REMARK ");
			strSql.Append(" FROM P_DDCODE ");
			strSql.Append(" where DDID=:DDID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DDID", OracleType.VarChar,50)};
			parameters[0].Value = DDID;

			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["DDID"]!=null && ds.Tables[0].Rows[0]["DDID"].ToString()!="")
				{
					this.DDID=ds.Tables[0].Rows[0]["DDID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["DDTYPE"]!=null && ds.Tables[0].Rows[0]["DDTYPE"].ToString()!="")
				{
					this.DDTYPE=ds.Tables[0].Rows[0]["DDTYPE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CODEID"]!=null && ds.Tables[0].Rows[0]["CODEID"].ToString()!="")
				{
					this.CODEID=ds.Tables[0].Rows[0]["CODEID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CODENAME"]!=null && ds.Tables[0].Rows[0]["CODENAME"].ToString()!="")
				{
					this.CODENAME=ds.Tables[0].Rows[0]["CODENAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ORDERID"]!=null && ds.Tables[0].Rows[0]["ORDERID"].ToString()!="")
				{
					this.ORDERID=decimal.Parse(ds.Tables[0].Rows[0]["ORDERID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["REMARK"]!=null && ds.Tables[0].Rows[0]["REMARK"].ToString()!="")
				{
					this.REMARK=ds.Tables[0].Rows[0]["REMARK"].ToString();
				}
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM P_DDCODE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

